<?php
	session_start();

	require_once("includes/connect.php");
	require_once("includes/function.php");


	$db = NEW myDBs();
	$db->selectDB("account");

	$sql = "SELECT DISTINCT tbl_utility.*, panngan2_name, panngan3_name, expenses1_name, expenses2_name
			FROM tbl_utility, panngan2, panngan3, expenses_lvl1, expenses_lvl2
			WHERE lvl1_id = '" .$_SESSION["lvl1_id"]. "'
			AND tbl_utility.panngan2_id = panngan2.panngan2_id
			AND tbl_utility.panngan3_id = panngan3.panngan3_id
			AND tbl_utility.ex1_id = expenses_lvl1.expenses1_id
			AND tbl_utility.ex2_id = expenses_lvl2.expenses2_id
			ORDER BY utility_id
			";
	
	//echo $sql;
	$result = $db->runSQL($sql);
	//$rows = $db1->fetch_object($result);

?>

<script type="text/javascript">
	$(document).ready(function(){
		$("#example").dataTable();

		$("#add_new").click(function() {
			//alert("adfs");
			$('<div>').dialog2({
				autoOpen: true,
				title: "เพิ่มฎีกา",
				content: "dlg_add_pet.php",
				id: "modal-chkJob"
			});
		});

	});

	function edit(utility_id)  {
			//alert("adfs");
		$('<div>').dialog2({
			autoOpen: true,
			title: "แก้ไขฎีกา",
			content: "dlg_add_pet.php?utility_id=" + utility_id,
			id: "modal-chkJob"
		});

	}

	function del(utility_id)  {
			//alert("adfs");
		if (confirm("คุณแน่ใจที่ต้องการลบรายการนี้ใช่ไหม?"))
		{
			$.post("process_utility.php", {utility_id: utility_id, task: 'del'}, function() {window.location.href="index.php?pages=frm_petition_utility&pageid=9";});
		}

	}

	
</script>


<button class="btn primary" id="add_new">เพิ่มฎีกาสาธารณูปโภค</button>
<table id="example" class="table table-bordered" width="100%" >
	<caption><br></caption>
	<thead>
		<tr>
			<th>#</th>
			<th>เลขที่ฎีกา</th>
			<th>แผนงาน</th>
			<th>งาน</th>
			<th>หมวด</th>
			<th>ประเภท</th>
			<th>จำนวนเงิน</th>
			<th>action</th>
		</tr>
	</thead>
	<tbody>	
<?php


	$i=0;
	while ($rows = $db->fetch_object($result)) {
		$i++;
		
		echo "<tr>
					<td>$i</td>
					<td>$rows->pet_id</td>
					<td>$rows->panngan2_name</td>
					<td>$rows->panngan3_name</td>
					<td>$rows->expenses1_name</td>
					<td>$rows->expenses2_name</td>
					<td>".number_format($rows->utility, 2).  "</td>
					<td><a href='javascript:edit($rows->utility_id)'><i class='icon-pencil'></i></a>&nbsp;|&nbsp;<a href='javascript:del($rows->utility_id)'><i class='icon-remove'></i></a>&nbsp;|&nbsp;<a href='prt_utility.php?utility_id=$rows->utility_id' target='_blank'><i class='icon-print'></i></a></td>
				</tr>
				";
		
	}

?>

</tbody>
</table>
